package com.example.shoppingmallclient.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.shoppingmallclient.R;
import com.example.shoppingmallclient.pojo.OrderItem;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 袁梦达 2019012364
 */
public class OrderListAdapter extends BaseAdapter {

    private List<OrderItem> productList = new ArrayList<>();
    private int layoutResId;
    private Context context;
    private TextView tvOrderId;
    private TextView tvOrderTime;
    private TextView tvOrderQuantity;
    private TextView tvOrderSumPrice;

    public OrderListAdapter(List<OrderItem> productList, int layoutResId, Context context) {
        this.productList = productList;
        this.layoutResId = layoutResId;
        this.context = context;
    }
    @Override
    public int getCount() {
        if(productList != null){
            return productList.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        if(productList != null){
            return productList.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if(convertView == null){
            LayoutInflater inflater = LayoutInflater.from(context);
            convertView = inflater.inflate(layoutResId, null, false);
        }

        tvOrderId = convertView.findViewById(R.id.tv_order_id);
        tvOrderTime = convertView.findViewById(R.id.tv_order_time);
        tvOrderQuantity = convertView.findViewById(R.id.tv_order_quantity);
        tvOrderSumPrice = convertView.findViewById(R.id.tv_order_sumPrice);

        tvOrderId.setText("订单编号" + productList.get(position).getOrderId());
        tvOrderTime.setText("下单时间" + productList.get(position).getOrderTime());
        tvOrderQuantity.setText("商品数量" + productList.get(position).getQuantity());
        tvOrderSumPrice.setText("总价" + productList.get(position).getSumPrice());

        return convertView;
    }
}
